Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

462
Visualizações
Receiving [Ljava.lang.Object in Apps Script (bringing attachment name from Gmail to Sheets)

Have been working on an Apps Script to bring Gmail message information (sender, subject, link, attachment) into a Google Sheet, but not able to bring the title of the attachment over successfully (attachment name field in Google Sheet reads like [Ljava.lang.Object;@127afe9; it appears to be related to the attachments array, but I cannot figure it out. Have tried the solutions offered in What does "[Ljava.lang.Object;@" mean?, but no luck.

function emailToSheet() {
  var label = GmailApp.getUserLabelByName('New TODO'); // Find messages with label
  var changeLabel = GmailApp.getUserLabelByName('TODO'); // Change message label to
  var ss = SpreadsheetApp.openById('xxxx'); // Append to spreadsheet
  var sh = ss.getSheetByName("Email"); //On this sheet

  var threads = label.getThreads();
  for (var i=0; i<threads.length; i++){

    var messages = threads[i].getMessages();
    for (var j=0; j<messages.length; j++)  {

      var sent = messages[j].getDate();
      var from = messages[j].getFrom();
      var subject = messages[j].getSubject();

      // Get attachment name
      var attachments = messages[j].getAttachments();
      var attachmentName = [];
      for (var k=0; k<attachments.length; k++) {
        var attachmentName = attachments[k].getName();
      }

      var messageId = messages[j].getId();
      var messageUrl = "https://mail.google.com/mail/u/0/#inbox/" + messageId;

      ss.appendRow([sent, from, subject, attachmentName, messageUrl])
    }
    threads[i].removeLabel(label);
    threads[i].addLabel(changeLabel);
  }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm thinking that you want this:

  var attachmentName = [];
  for (var k=0; k<attachments.length; k++) {
    var attachmentName = attachments[k].getName();
  }

to be this:

   var attachmentName = [];
  for (var k=0; k<attachments.length; k++) {
    attachmentName.push(attachments[k].getName());
  }

and maybe this:

  ss.appendRow([sent, from, subject, attachmentName, messageUrl])

to be this:

  ss.appendRow([sent, from, subject, attachmentName.join(" "), messageUrl])
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda